package com.chenlonghai.sbmybatis.config.dao;

import java.beans.PropertyVetoException;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
//配置mybatis mapper的扫描路径
@MapperScan("com.chenlonghai.sbmybatis.dao")
public class DataSourceConfiguration {
	
	@Value("${jdbc.driver}")
	private String jdbcDriver; 
	@Value("${jdbc.url}")
	private String jdbcUrl;
	@Value("${jdbc.username}")
	private String user;
	@Value("${jdbc.password}")
	private String  password;
  @Bean(name="dataSource")
  public ComboPooledDataSource createDataSource() throws PropertyVetoException {
	  
	  ComboPooledDataSource dataSource = new ComboPooledDataSource();
	  dataSource.setDriverClass(jdbcDriver);
	  dataSource.setJdbcUrl(jdbcUrl);
	  dataSource.setUser(user);
	  dataSource.setPassword(password);
	  //关闭连接不自动提交
	  dataSource.setAutoCommitOnClose(false);  
	  return dataSource;
	  
  }
	

}
